﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="../styles/js-console.css" rel="stylesheet" />
</head>
<body>    
    <div id="js-console"></div>
    <script src="../scripts/js-console.js"></script>
    <script>
        var numbers = [12, 34, 45, 6, 7, 0, 100, 150, 4, 45, 150, 12, 16, 88, 280, 94, 34, 15, 15, 1, 34, 34, 34];        

        function countNumberOccurances(array) {
            var maximalArrayValue = Math.max.apply(Math, array);

            var occurances = new Array(maximalArrayValue);

            for (var i = 0; i < array.length; i++) {
                if (occurances[array[i]] == undefined) {
                    occurances[array[i]] = 0;
                }

                occurances[array[i]]++;
            }

            for (var i = 0; i < occurances.length; i++) {
                if (occurances[i] == undefined) {
                    occurances[i] = 0;
                }
            }

            for (var i = 0; i < occurances.length; i++) {
                if (occurances[i] != 0) {
                    jsConsole.writeLine(i + '-' + occurances[i]);
                }
            }
        }

        countNumberOccurances(numbers);
    </script>
</body>
</html>
